$("#form-productInfo-edit").validate({
	rules:{
		productName:{
			required:true,
		},
		productPrice:{
			required:true,
		},
		productTerm:{
			required:true,
		},
	},
	submitHandler:function(form){
		edit();
	}
});

function edit() {
	var productId = $("input[name='productId']").val();
	var productName = $("input[name='productName']").val();
	var productPrice = $("input[name='productPrice']").val();
	var productTerm = $("input[name='productTerm']").val();
	var typeId = $("select[name='typeId']").val();
	var typeName = $("select[name='typeId'] option:selected").text();
	if(typeName ==null){
		typeName = $("input[id='typeIds']").val();
	}
	var specId = $("select[name='specId']").val();
	var specName = $("select[name='specId'] option:selected").text();
	if(specName ==null){
		specName = $("input[id='specIds']").val();
	}
	var isArrival = $("input[name='isArrival']").is(':checked') == true ? 1 : 0;
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx + "module/productInfo/save",
		data : {
			"productId": productId,
			"productName": productName,
			"productPrice": productPrice,
			"productTerm": productTerm,
			"typeId": typeId,
			"typeName": typeName,
			"specId": specId,
			"specName": specName,
			"isArrival": isArrival,
		},
		async : false,
		error : function(request) {
			$.modalAlert("系统错误", "error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("新增成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
					$.parentReload();
				});
			} else {
				$.modalAlert(data.msg, "error");
			}

		}
	});
}

function changeSelect(){
	var typeId = $("select[name='typeId']").val();
	$.ajax({
        type: "GET",
        url: ctx + "module/productSpecification/selectList",
        data : {
        	"typeId": typeId
        },
        success: function(result) {
        	//获取第二个下拉框的对象
        	var spec = document.getElementById('specId');
        	//每次获取数据前先清空
        	$(spec).empty();
        	for(var i=0;i<result.length;i++){//循环遍历数组
        		//将数组的值依次赋给第二个下拉框
        		spec[i] = new Option(result[i].specName,result[i].specId);
			}
        }
    });
}